/**
 * 返回当前日期和时间的年月日时分，格式为 YYYY-MM-DD HH:mm
 * @returns {string} 格式化后的日期时间字符串
 */
const getDateTime = () => {
  const now = new Date()
  const year = now.getFullYear()
  // 月份从 0 开始，所以要加 1，并且补零
  const month = String(now.getMonth() + 1).padStart(2, '0')
  const day = String(now.getDate()).padStart(2, '0')
  const hours = String(now.getHours()).padStart(2, '0')
  const minutes = String(now.getMinutes()).padStart(2, '0')

  return `${year}-${month}-${day} ${hours}:${minutes}`
}
const switchtime = (time) => {
  const year = time.getFullYear()
  // 月份从 0 开始，所以要加 1，并且补零
  const month = String(time.getMonth() + 1).padStart(2, '0')
  const day = String(time.getDate()).padStart(2, '0')
  const hours = String(time.getHours()).padStart(2, '0')
  const minutes = String(time.getMinutes()).padStart(2, '0')

  return `${year}-${month}-${day} ${hours}:${minutes}`
}

export { getDateTime, switchtime }
